package com.PTRS.dao;

import com.PTRS.entities.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ICourseDao {
    //查询所有
    @Select("SELECT * FROM course")
    @Results(
            id = "courseMap",value = {
                    @Result(id = true,column = "id",property = "courseID"),
                    @Result(column = "start_time",property = "courseStartTime"),
                    @Result(column = "end_time",property = "courseEndTime"),
                    @Result(column = "name",property = "courseName"),
                    @Result(column = "intro",property = "courseIntro"),
                    @Result(column = "opened_by",property = "courseOpenedBy"),
                    @Result(column = "price_per_day",property = "coursePricePerDay")
    }
    )
    List<Course> findAll();

    //插入课程
    @Insert("INSERT INTO course(start_time, end_time, name, intro, opened_by,price_per_day) VALUES (#{courseStartTime},#{courseEndTime},#{courseName},#{courseIntro},#{courseOpenedBy},#{coursePricePerDay})")
    void insertCourse(Course course);

    //修改课程
    @Update("UPDATE course SET start_time=#{courseStartTime},end_time=#{courseEndTime},name=#{courseName},intro=#{courseIntro},opened_by=#{courseOpenedBy},price_per_day=#{coursePricePerDay} WHERE id=#{courseID}")
    void updateCourse(Course course);

    //删除课程
    @Delete("DELETE FROM course WHERE id=#{courseID}")
    void deleteCourse(int courseID);

    //查找课程，参数为id
    @Select("SELECT * FROM course WHERE id=#{courseID}")
    @ResultMap("courseMap")
    Course findCourseByID(int courseID);
}
